package dk.itu.spvc.tourtracker.gui;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.location.LocationManager;

import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;

import dk.itu.spvc.tourtracker.model.CurrentState;

public class DisplayOverlay extends Overlay {
	
	// PRIVATE FIELDS
	
	// Debug
	//private static final String TAG = "TourTracker";
	//private static final boolean D = true;
	
	private Paint rectanglePaint;
	private Paint textPaint;
	
	private String tripName;
	private String locationProvider;
	private int state;
	
	// CTOR
	
	public DisplayOverlay() {				
		rectanglePaint = new Paint();
        rectanglePaint.setAntiAlias(true);
        rectanglePaint.setARGB(100, 255, 255, 255);		
        textPaint = new Paint();
        textPaint.setTextSize(24);
        textPaint.setARGB(255, 0, 0, 0);
	}
	
	// OVERRIDES
	
	@Override
    public void draw(Canvas canvas, MapView mapview, boolean shadow) {
        super.draw(canvas, mapview, shadow);
                       
        if (tripName == "") return;
        
        int w = canvas.getWidth();
        int x = w / 4;
       
        canvas.drawRect(x, 30, x * 3, 90, rectanglePaint);        
        canvas.drawText("Tour \"" + tripName + "\" " + getLocationProvider(), x + 10, 55, textPaint);
        canvas.drawText(getNamedState(state), x + 10, 80, textPaint);
    }
	
	// METHODS
	
    public void setText(String tripName, int state, String locationProvider){
        this.tripName = tripName;
        this.state = state;
        this.locationProvider = locationProvider;
    }
    
    public static String getNamedState (int state) {
    	String namedState = "";
        switch (state){
	        case CurrentState.VIEW:
				namedState = "";
				break;
			case CurrentState.RECORD:
				namedState = "Recording...";
				break;
			case CurrentState.PAUSED:
				namedState = "Paused";
				break;
        }
        return namedState;
    }
    
    private String getLocationProvider() {
    	if (locationProvider == null) {
    		return "";
    	} 
    	else if (locationProvider.contentEquals(LocationManager.GPS_PROVIDER)) {
    		return "GPS";
    	}
    	else if (locationProvider.contentEquals(LocationManager.NETWORK_PROVIDER)) {
    		return "NET";
    	}
    	return "";
    }
    
}
